// STL includes
#include <vector>
#include <string>

// C includes

// Library includes
#include <cxxtest/TestSuite.h>

// Project includes
#include <PinControl.h>
#include <Updater.h>
#include <Globals.h>

using namespace std;
using namespace Tictocs;

extern "C" void mock_time_reset(void);

class PinControlTestSuite: public CxxTest::TestSuite
{
  static const int pin_number = 10;
  static const uint8_t signal_high = 1, signal_low = 2;

  struct emitter: public Connectable
  {
    void high(void)
    {
      emit(signal_high);
    }
    void low(void)
    {
      emit(signal_low);
    }
    emitter(Connector& conn): Connectable(conn) {}
  };

  PinControl* ppinc;
  Updater* pUpdater;
  Connector* pConnector;
  emitter* pemit;
public:
  void setUp()
  {
    mock_time_reset();

    pUpdater = new Updater();
    pConnector = new Connector();
    ppinc = new PinControl(*pConnector,pin_number,signal_low,signal_high);
    pemit = new emitter(*pConnector);
    ppinc->begin();
    ppinc->listen(pemit);
  }
  void tearDown()
  {
    delete ppinc;
    delete pConnector;
    delete pUpdater;
    theLogger.setVerbose(false);
  }
  void testBegin()
  {
    TS_ASSERT_EQUALS(digitalRead(pin_number),0);
  }
  void testEmitHigh()
  {
    pemit->high();
    TS_ASSERT_EQUALS(digitalRead(pin_number),1);
  }
  void testEmitLow()
  {
    thePins.hwSetDigital(pin_number,1);
    pemit->low();
    TS_ASSERT_EQUALS(digitalRead(pin_number),0);
  }
};
// vim:cin:ai:sts=2 sw=2 ft=cpp
